package com.day10.objectdemo;

public class Student {
    private String stuName;
    private int stuAge;
    private String stuGender;

    public Student() {
    }

    public Student(String stuName, int stuAge, String stuGender) {
        this.stuName = stuName;
        this.stuAge = stuAge;
        this.stuGender = stuGender;
    }

    public String getStuName() {
        return stuName;
    }

    public void setStuName(String stuName) {
        this.stuName = stuName;
    }

    public int getStuAge() {
        return stuAge;
    }

    public void setStuAge(int stuAge) {
        this.stuAge = stuAge;
    }

    public String getStuGender() {
        return stuGender;
    }

    public void setStuGender(String stuGender) {
        this.stuGender = stuGender;
    }

    // toString()方法的作用就是将一个对象变成字符串的形式。
    @Override
    public String toString() {
        // return super.toString();
        return "学员姓名："+stuName+",学员年龄："+stuAge+",学员性别："+stuGender;
    }

    @Override
    public boolean equals(Object obj) {
        boolean flag = false;
        if(this == obj){// 如果参数对象和调用方法对象来自于同一个内存地址，则返回true
            flag = true;
        }else{// 如果参数对象和调用方法对象不是同一个地址的对象，则首先考虑是否是同一个类的对象。
            if(obj instanceof Student){// obj是Student类的对象，可以比较
                Student stu = (Student)obj;
                if(this.getStuName().equals(stu.getStuName())
                        &&this.getStuAge()==stu.getStuAge()
                        &&this.getStuGender().equals(stu.getStuGender())){// 参数对象和调用方法对象的属性完全相等，则判定两个对象相等。
                    flag = true;
                }
            }
        }
        return flag;
    }

}
